package com.yang.servletdemo.controller;

import com.yang.servletdemo.model.Weather;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/weather")
public class WeatherController {

    @GetMapping("/get")
    public Weather getWeatherById(@RequestParam(value = "id", required = false) Integer id) {
        Weather zz = new Weather(0, "郑州", "晴", "sun.png", 32.8);
        Weather bj = new Weather(1, "北京", "晴转多云", "cloud_sun.png", 23.2);
        Weather sh = new Weather(2, "上海", "雨", "clouds.png", 15.4);
        Weather gz = new Weather(3, "广州", "雾霾", "clouds.png", 23.5);
        Weather xa = new Weather(4, "西安", "多云转晴", "cloud_sun.png", 34.1);
        switch (id) {
            case 0:
                return zz;
            case 1:
                return bj;
            case 2:
                return sh;
            case 3:
                return gz;
            case 4:
                return xa;
            default:
                return zz;
        }
    }
}
